#include "ADC.h"

void ADC_init(void) 
{
	CTRL1 = 0b0101000000000010;
	CTRL2 = 0b0000000000001001;
	POWER = 0b0000000010100100;
	CAL = 0b0000000000000000;
	PANPAR = 0xFFFF;
	CTRL1 &= 0xBFFF;
	while(POWER & POWER_PSTS0_BITMASK);
	while(POWER & POWER_PSTS1_BITMASK);
	CTRL1 |= 0x2000;
}

uint16 ADonce(uint16 ANn) 
{
	uint16 result;
	while(ADSTAT & (1 << ANn) == 0);
	result = (ADRSLT(ANn) & 0x7FF8) >> 3;
	return result;
}